package o;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;

import androidx.viewpager.widget.ViewPager;

import com.huawei.hms.api.HuaweiApiAvailability;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class AccountLoginChecker {
    private static final AccountLoginChecker ˎ = new AccountLoginChecker();
    private final List<eoi> ˊ = new ArrayList();
    private final ExecutorService ˋ = Executors.newFixedThreadPool(1);
    private final AtomicBoolean ˏ = new AtomicBoolean(false);
    private Runnable ॱ;

    ViewPager
    private AccountLoginChecker() {
    }

    public static AccountLoginChecker ˏ() {
        return ˎ;
    }

    private static boolean ˋ(Context context, Intent intent) throws ActivityNotFoundException {
        if (!(context instanceof Activity) || ((Activity) context).isFinishing()) {
            return false;
        }
        try {
            Logger.ˋ("AccountLoginChecker", "tryStartActivityForResult, activity: " + context);
            ((Activity) context).startActivityForResult(intent, 2018);
            return true;
        } catch (ActivityNotFoundException e) {
            throw e;
        } catch (Exception e2) {
            Logger.ˋ("AccountLoginChecker", "Exception when calling startActivityForResult.");
            return false;
        }
    }

    private static Runnable ˋ(final CountDownLatch countDownLatch) {
        return new Runnable() {
            public void run() {
                countDownLatch.countDown();
            }
        };
    }

    private synchronized void ॱ(eoi o_eoi) {
        this.ˊ.add(o_eoi);
    }

    private synchronized void ˎ(int i) {
        Logger.ˎ("AccountLoginChecker", "Callback checkAccountLogin.");
        Iterator it = this.ˊ.iterator();
        while (it.hasNext()) {
            ((eoi) it.next()).ˎ(i);
            it.remove();
        }
    }

    boolean ॱ(Context context) {
        int ॱ = eof.ॱ(context);
        Logger.ˏ("AccountLoginChecker", "HwID has login: " + ॱ);
        if (ॱ == 1) {
            return true;
        }
        return false;
    }

    void ˊ(final Context context, eoi o_eoi) {
        if (context == null || o_eoi == null) {
            throw new NullPointerException("context or fireCheckLoginResult must not be null.");
        }
        Logger.ˎ("AccountLoginChecker", "Call checkAccountLogin.");
        if (((eov) cdb.ॱ(eov.class)).ॱ(context)) {
            o_eoi.ˎ(0);
            return;
        }
        ॱ(o_eoi);
        if (!this.ˏ.get()) {
            this.ˏ.set(true);
            this.ˋ.execute(new Runnable(this) {
                final /* synthetic */ AccountLoginChecker ˋ;

                public void run() {
                    this.ˋ.ˏ(context);
                    this.ˋ.ˏ.set(false);
                }
            });
        }
    }

    private void ˏ(Context context) {
        int ॱ = eof.ॱ(context);
        Logger.ˏ("AccountLoginChecker", "HwID has login: " + ॱ);
        if (ॱ == -1) {
            try {
                ˋ(context, 800);
            } catch (InterruptedException e) {
                Logger.ˋ("AccountLoginChecker", "The thread is interrupted, that for checking whether the account is logged in.");
            }
            ॱ = eof.ॱ(context);
            Logger.ˏ("AccountLoginChecker", "HwID has login: " + ॱ);
        }
        ˎ(ॱ);
    }

    private void ˋ(Context context, long j) throws InterruptedException {
        boolean z = true;
        Intent intent = new Intent();
        intent.setClassName("com.huawei.hwid", HuaweiApiAvailability.ACTIVITY_NAME);
        intent.putExtra("intent.extra.hms.core.DELEGATE_NAME", "Startup.Jump");
        if (context.getPackageManager().resolveActivity(intent, 0) == null) {
            Logger.ˋ("AccountLoginChecker", "Not exist HwID");
            return;
        }
        CountDownLatch countDownLatch = new CountDownLatch(1);
        this.ॱ = ˋ(countDownLatch);
        try {
            if (!ˋ(context, intent)) {
                Logger.ˎ("AccountLoginChecker", "The context is not an activity.");
                intent.setFlags(268435456);
                context.startActivity(intent);
            }
            if (countDownLatch.await(j, TimeUnit.MILLISECONDS)) {
                z = false;
            }
            Logger.ˎ("AccountLoginChecker", "Try to start HwID, timeout: " + z);
        } catch (ActivityNotFoundException e) {
            Logger.ˋ("AccountLoginChecker", "Not exist HwID");
        } catch (Throwable e2) {
            Logger.ˋ("AccountLoginChecker", "Exception when calling startActivity.", e2);
        }
    }

    public void ˊ(int i, int i2, Intent intent) {
        if (this.ॱ != null && i == 2018) {
            Logger.ˎ("AccountLoginChecker", "Received the result of starting Hwid.");
            this.ॱ.run();
            this.ॱ = null;
        }
    }
}
